/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RendreSequentielPnl.java
 *
 * Created on 21 nov. 2011, 22:33:42
 */
package com.sma.renamefilewindows.ihm.panel;

import com.sma.renamefilewindows.ihm.FrameContainer;
import com.sma.renamefilewindows.utils.StringUtils;
import com.sma.renamefilewindows.utils.classe.Couple;
import com.sma.renamefilewindows.utils.classe.PositionUtils;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

/**
 *
 * @author SMA
 */
public class RendreSequentielPnl extends javax.swing.JPanel implements UpdaterListeFichier{

    private FrameContainer parent;
    
    /** Creates new form RendreSequentielPnl */
    public RendreSequentielPnl(FrameContainer _parent) {
        initComponents();
        this.parent = _parent;
        this.buttonGroup1.add(this.radioNomExistant);
        this.buttonGroup1.add(this.radioNvNom);
        PositionUtils.initComboListPosition(this.positionTexte);
        Separations.initJComboBoxSeparationTexte(this.separationTexte);
        this.nouveauNom.setText("exemple");
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        radioNomExistant = new javax.swing.JRadioButton();
        radioNvNom = new javax.swing.JRadioButton();
        nouveauNom = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        positionTexte = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        debutNumeratation = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        separationTexte = new javax.swing.JComboBox();

        jLabel1.setText("Ajout le n° à ");

        radioNomExistant.setSelected(true);
        radioNomExistant.setText("nom d'élément existant");
        radioNomExistant.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                radioNomExistantStateChanged(evt);
            }
        });

        radioNvNom.setText("nouveau nom");
        radioNvNom.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                radioNvNomStateChanged(evt);
            }
        });

        nouveauNom.setText("jTextField1");
        nouveauNom.setEnabled(false);
        nouveauNom.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                nouveauNomKeyReleased(evt);
            }
        });

        jLabel2.setText("Placer le numéro");

        positionTexte.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        positionTexte.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                positionTexteItemStateChanged(evt);
            }
        });

        jLabel3.setText("Commencer les numéros à");

        debutNumeratation.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                debutNumeratationStateChanged(evt);
            }
        });

        jLabel4.setText("séparés par");

        separationTexte.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        separationTexte.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                separationTexteItemStateChanged(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel4)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(radioNomExistant)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(radioNvNom)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(nouveauNom, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, separationTexte, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, positionTexte, 0, 149, Short.MAX_VALUE))
                        .add(5, 5, 5)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(debutNumeratation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(radioNomExistant)
                    .add(radioNvNom)
                    .add(nouveauNom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, debutNumeratation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jLabel2)
                        .add(positionTexte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jLabel3)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(separationTexte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void radioNvNomStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_radioNvNomStateChanged
    radioNomChanged();
}//GEN-LAST:event_radioNvNomStateChanged

private void radioNomExistantStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_radioNomExistantStateChanged
    radioNomChanged();
}//GEN-LAST:event_radioNomExistantStateChanged

private void positionTexteItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_positionTexteItemStateChanged
    setExemple();
}//GEN-LAST:event_positionTexteItemStateChanged

private void separationTexteItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_separationTexteItemStateChanged
    setExemple();
}//GEN-LAST:event_separationTexteItemStateChanged

private void nouveauNomKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nouveauNomKeyReleased
    setExemple();
}//GEN-LAST:event_nouveauNomKeyReleased

private void debutNumeratationStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_debutNumeratationStateChanged
    setExemple();
}//GEN-LAST:event_debutNumeratationStateChanged

    private void radioNomChanged() {
        if (this.radioNvNom.isSelected()) {
            this.nouveauNom.setEditable(true);
            this.nouveauNom.setEnabled(true);
        } else {
            this.nouveauNom.setEditable(false);
            this.nouveauNom.setEnabled(false);
        }
        setExemple();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JSpinner debutNumeratation;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField nouveauNom;
    private javax.swing.JComboBox positionTexte;
    private javax.swing.JRadioButton radioNomExistant;
    private javax.swing.JRadioButton radioNvNom;
    private javax.swing.JComboBox separationTexte;
    // End of variables declaration//GEN-END:variables

    private void setExemple(){
        if(!this.parent.isInitialisation()){
            String texteExemple = this.radioNomExistant.isSelected() ? FrameContainer.NAMES_FILES_EXEMPLE : this.nouveauNom.getText();
            Couple<PositionUtils.Position> couplePosition = (Couple<PositionUtils.Position>)this.positionTexte.getSelectedItem();
            Couple<Separations.SeparationsEnum> coupleSeparation = (Couple<Separations.SeparationsEnum>)this.separationTexte.getSelectedItem();
            String texte = StringUtils.rendreSequentiel(texteExemple,couplePosition.getEnumObject(), coupleSeparation.getEnumObject(), ((Integer)this.debutNumeratation.getValue()).intValue());
            this.parent.setLabelExemple(texte);
            //rendreSequentiel
            //StringUtils.rendreSequentiel(this.parent.getLstFichier(), couplePosition.getEnumObject(), coupleSeparation.getEnumObject(), ((Integer)this.debutNumeratation.getValue()).intValue(), !this.radioNomExistant.isSelected(),this.nouveauNom.getText());
        }
    }

    @Override
    public void updateListeFichier() {
                    String texteExemple = this.radioNomExistant.isSelected() ? FrameContainer.NAMES_FILES_EXEMPLE : this.nouveauNom.getText();
            Couple<PositionUtils.Position> couplePosition = (Couple<PositionUtils.Position>)this.positionTexte.getSelectedItem();
            Couple<Separations.SeparationsEnum> coupleSeparation = (Couple<Separations.SeparationsEnum>)this.separationTexte.getSelectedItem();
            String texte = StringUtils.rendreSequentiel(texteExemple,couplePosition.getEnumObject(), coupleSeparation.getEnumObject(), ((Integer)this.debutNumeratation.getValue()).intValue());
            StringUtils.rendreSequentiel(this.parent.getLstFichier(), couplePosition.getEnumObject(), coupleSeparation.getEnumObject(), ((Integer)this.debutNumeratation.getValue()).intValue(), !this.radioNomExistant.isSelected(),this.nouveauNom.getText());
    }
    public static class Separations {

        public static interface LibelleAction {

            public static final String TRAIT_SOULIGNEMENT = "Trait de soulignement";
            public static final String AUCUN = "Aucun";
        }

        public static enum SeparationsEnum {

            TRAIT_SOULIGNEMENT, AUCUN
        }

        public static void initJComboBoxSeparationTexte(JComboBox comboBoxAction) {
            comboBoxAction.removeAllItems();
            comboBoxAction.addItem(new Couple<SeparationsEnum>(SeparationsEnum.AUCUN, LibelleAction.AUCUN));
            comboBoxAction.addItem(new Couple<SeparationsEnum>(SeparationsEnum.TRAIT_SOULIGNEMENT, LibelleAction.TRAIT_SOULIGNEMENT));
        }
    }
}
